import Vue       from 'vue';
import ElementUI from 'element-ui';

import App               from './app.vue'
import Bus               from './assets/bus';
import router            from './routes'
import store             from './store'
import { hasPermission } from "./assets/permission";
import './validatePermission';

Vue.use(ElementUI);
Bus(Vue);

/**
 * Next, we will create a fresh Vue application instance and attach it to
 * the page. Then, you may begin adding components to this application
 * or customize the JavaScript scaffolding to fit your unique needs.
 */

Vue.prototype.$hasPermission = (permission = '') => {

    let permissionsName = store.getters[ 'Auth/permission' ];
    if (!permissionsName || !permissionsName.length) return false;
    permission = [].concat(permission);

    return hasPermission(permissionsName, permission);
};

Vue.prototype.$hasRole = (role = '') => {

    let rolesName = store.getters[ 'Auth/rolesName' ];

    if (!rolesName || !rolesName.length) return false;

    role = [].concat(role);

    return hasPermission(rolesName, role, 'admin');
};

const app = new Vue({
    el    : '#app',
    router,
    store,
    render: h => h(App)
});

export default app;
